package com.bkhc.partner.repository;

import com.bkhc.common.util.CommonUtil;
import com.bkhc.common.util.response.PageUtil;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.common.vo.OrderItemVo;
import com.bkhc.common.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class OrderRepository {
    @Autowired
    private RestTemplate restTemplate;


    public PageUtil getPartnerCodeOrders(OrderVo order, int pageNum, int pageSize) {
        String serviceName = "ORDER-APP";
        String url = "http://" + serviceName + "/order/order/list/partner?" +
                "pageIndex="+pageNum
                +"&pageSize="+pageSize;
        Map<String,Object> params = new HashMap<>();
        params.put("userId",order.getUserId());
        params.put("username",order.getUsername());
        params.put("receiver",order.getReceiver());
        params.put("brandCode",order.getBrand());
        params.put("brandName",order.getBrandName());
        params.put("productName",order.getProductName());
        params.put("orderCode",order.getOrderCode());
        params.put("orderAuditStatus",order.getOrderStatus());
        HttpEntity<Object> enetity = CommonUtil.buildParam(params);
        PageUtil result = restTemplate.postForObject(url.toString(), enetity, PageUtil.class);
//        PageUtil result = restTemplate.postForObject(url,productCodes, PageUtil.class);
        return result;
    }


    public void updateOrderAuditStatus(String orderCode,int auditStatus) {
        String serviceName = "ORDER-APP";
        String url = "http://" + serviceName + "/order/order/"+orderCode+"/updateOrderAuditStatus/"+auditStatus;

        HttpEntity<Object> enetity = CommonUtil.buildParam(null);
        PageUtil result = restTemplate.postForObject(url.toString(), enetity, PageUtil.class);
    }

}
